package com.baseproject.datasource.local.database.greendao;

import android.support.annotation.NonNull;

import com.baseproject.datasource.local.database.BaseLocalDatabaseStrategy;

import java.util.List;
import java.util.Map;

/**
 * Created by asus on 2017-09-18.
 */

public class GreenDaoStrategy implements BaseLocalDatabaseStrategy {

    @Override
    public <T> void insertItem(@NonNull T item) {
//        DaoSession daoSession = DaoMaster.newDevSession(BaseApplication.getApplication(), APPLICATION_NAME + ".db");
//        AbstractDao<T, Integer> abstractDao = (AbstractDao<T, Integer>) daoSession.getDao(item.getClass());
//        abstractDao.insert(item);
    }

    @Override
    public <T> void insertItems(@NonNull List<T> items) {
//        if (null == items || items.size() < 1) {
//            return;
//        }
//        DaoSession daoSession = DaoMaster.newDevSession(BaseApplication.getApplication(), APPLICATION_NAME + ".db");
//        AbstractDao<T, Integer> abstractDao = (AbstractDao<T, Integer>) daoSession.getDao(items.get(0).getClass());
//        abstractDao.insertInTx(items);
    }

    @Override
    public <T> List<T> getList(Class<T> className, Map<String, String> where, String[] projections) {
//        DaoSession daoSession = DaoMaster.newDevSession(BaseApplication.getApplication(), APPLICATION_NAME + ".db");
//        AbstractDao<T, Integer> abstractDao = (AbstractDao<T, Integer>) daoSession.getDao(className);
//        abstractDao.queryBuilder()
//                .where(abstractDao.Pro)

        return null;
    }

    @Override
    public <T> void delete(Class<T> className, Map<String, String> where) {

    }

    @Override
    public <T> void updateItem(@NonNull T item, Map<String, String> where) {

    }

    @Override
    public <T> void updateItems(@NonNull List<T> items, Map<String, String> where) {

    }

//    private <T> Class<?> getIdClassName(@NonNull T item) {
//        Field[] columnFields = item.getClass().getFields();
//        for (Field field : columnFields) {
//            field.setAccessible(true);
//        }
//        Field resultField = null;
//        for (Field field : columnFields) {
//            //找到列名与bean对象的成员变量的映射关系
//            Id anno = field.getAnnotation(Id.class);
//            if (anno != null) {
//                resultField = field;
//                break;
//            }
//        }
//        if (null != resultField) {
//            Class idClassName = resultField.getType();
//            return idClassName;
//        }
//        return Void.class;
//    }
}
